/* model */
import { 
  BaseSelectUserTree, 
  SelectUserComponentDepartment,
  SelectUserComponentRole,
  SelectUserComponentServiceProvider 
} from '@src/component/common/BaseSelectUser/model'

function transformServerTreeToComponentTree(
  serverTree: SelectUserComponentDepartment[] | SelectUserComponentRole[] | SelectUserComponentServiceProvider[]
): BaseSelectUserTree[] {
  
  let componentTree: BaseSelectUserTree[] = []
  
  serverTree.forEach((serverTreeItem: SelectUserComponentDepartment | SelectUserComponentRole | SelectUserComponentServiceProvider) => {
    
    // 是否为只显示的节点
    const isOnlyDisplay = (
      Boolean((serverTreeItem as SelectUserComponentRole)?.isCustomerServiceCloud) 
      || Boolean((serverTreeItem as SelectUserComponentRole)?.isServiceCloud)
      || Boolean((serverTreeItem as SelectUserComponentRole)?.isHideCheckbox)
    )
    
    let componentTreeItem: BaseSelectUserTree = {
      ...serverTreeItem,
      isOnlyDisplay
    } as BaseSelectUserTree
    
    componentTree.push(componentTreeItem)
    
  })
  
  return componentTree
}

export {
  transformServerTreeToComponentTree
}
